﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rappelz.GameServer
{
    public class ItemInstance
    {
        public enum GenerateCode : int
        {
            ByMonster = 0,
            ByMarket = 1,
            ByQuest = 2,
            ByScript = 3,
            ByMix = 4,
            ByGm = 5,
            ByBasic = 6,
            ByTrade = 7,
            ByDivide = 8,
            ByItem = 10,
            ByFieldProp = 11,
            ByAuction = 12,
            ByShoveling = 13,
            ByHuntaholic = 14,
            ByDonationReward = 15,
            ByUnknown = 126,
        }

        public enum ItemFlag : int
        {
            FlagNone = -1,
            FlagCard = 0,
            FlagFull = 1,
            FlagInserted = 2,
            FlagFailed = 3,
            FlagEvent = 4,
            FlagContainsPet = 5,
            FlagTaming = 29,
            FlagNonChaosStone = 30,
            FlagSummon = 31,
        }

        public enum FlagBits : uint
        {
            Card = 0x01,
            Full = 0x02,
            Inserted = 0x04,
            Failed = 0x08,
            Event = 0x10,
            ContainsPet = 0x20,
            Taming = 0x20000000,
            NonChaosStone = 0x40000000,
            Summon = 0x80000000,
        }

        public uint OwnerHandle;                            // 0x0
        public uint OwnSummonHandle;                        // 0x4
        public long UID;                                    // 0x8
        public int Code;                                    // 0x10
        public int nIdx;                                    // 0x14
        public int nLevel;                                  // 0x18
        public int nEnhance;                                // 0x1C
        public int nDurability;
        public int nOwnerUID;                               // 0x20
        public int nOwnSummonUID;                           // 0x24
        public int nAuctionID;                              // 0x28
        public int nItemKeepingID;                          // 0x2C
        public long nCount;                                 // 0x30
        public int nCurrentEndurance;                       // 0x38
        public long tExpire;                                // 0x40
        public Elemental.Type eElementalEffectType;         // 0x48
        public long tElementalEffectExpire;                 // 0x50
        public int nElementalEffectAttackPoint;             // 0x58
        public int nElementalEffectMagicPoint;              // 0x5C
        public uint Flag;                                   // 0x60
        public ItemInstance.GenerateCode GenerateInfo = GenerateCode.ByUnknown;      // 0x64
        public ItemBase.ItemWearType nWearInfo;             // 0x68
        public int[] Socket = new int[4];                   // 0x6C

        public void Copy(ItemInstance pFrom)
        {
            this.OwnerHandle = pFrom.OwnerHandle;
            this.OwnSummonHandle = pFrom.OwnSummonHandle;
            this.UID = pFrom.UID;
            this.Code = pFrom.Code;
            this.nIdx = pFrom.nIdx;
            this.nLevel = pFrom.nLevel;
            this.nEnhance = pFrom.nEnhance;
            this.nOwnerUID = pFrom.nOwnerUID;
            this.nOwnSummonUID = pFrom.nOwnSummonUID;
            this.nAuctionID = pFrom.nAuctionID;
            this.nItemKeepingID = pFrom.nItemKeepingID;
            this.nCount = pFrom.nCount;
            this.nCurrentEndurance = pFrom.nCurrentEndurance;
            this.tExpire = pFrom.tExpire;
            this.eElementalEffectType = pFrom.eElementalEffectType;
            this.tElementalEffectExpire = pFrom.tElementalEffectExpire;
            this.nElementalEffectAttackPoint = pFrom.nElementalEffectAttackPoint;
            this.nElementalEffectMagicPoint = pFrom.nElementalEffectMagicPoint;
            this.Flag = pFrom.Flag;
            this.GenerateInfo = pFrom.GenerateInfo;
            this.nWearInfo = pFrom.nWearInfo;
            this.Socket[0] = pFrom.Socket[0];
            this.Socket[1] = pFrom.Socket[1];
            this.Socket[2] = pFrom.Socket[2];
            this.Socket[3] = pFrom.Socket[3];
        }
    }
}
